const Koa = require('koa')
const router = require('koa-router')()
const bodyParser = require('koa-bodyparser')
const app = new Koa()

app.use(bodyParser())

router.get('/user', async (ctx, next) => {
  ctx.response.body = 
  `
    <form action="/user/register" method="post">
      <input type="text" name="name" placeholder="max">
      <br/>
      <input type="password" name="password" placeholder="123">
      <br/>
      <button>GOGOGO</button>
    </form> 
  `
})

router.post('/user/register', async (ctx, next) => {
  const {name, password} = ctx.request.body
  if(name === "max" && password === "123"){
    ctx.response.body = `登录成功, ${name}!`
  } else {
    ctx.response.body = `用户名或密码错误`
  }
})

app.use(router.routes())

app.listen(3000, () => {
  console.log('server is running at http://localhost:3000')
})

